package scrape;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class PostMethodExample {

  public static void main(String args[]) {

    HttpClient client = new HttpClient();
    client.getParams().setParameter("http.useragent", "Test Client");

    BufferedReader br = null;

    PostMethod method = new PostMethod("http://www.game.es/buscador/resultados.aspx?Txtproducto=&familia=PS3&genero=&categoria=&DdlPrecio=&DdlEdad=&DdlStock=&DllOrden=0&con=143434324fsd276g");
    method.addParameter("__EVENTTARGET", "MyDataGrid$ctl19$ctl01");
    method.addParameter("__EVENTARGUMENT", "");
    method.addParameter("__VIEWSTATE", "/wEPDwUJOTAwMDYwNzA0D2QWCmYPDxYCHgRUZXh0ZWRkAgIPZBYGZg8PFgIfAAUEMCwwMGRkAgEPDxYCHwAFATBkZAIFDzwrAAsAZAIED2QWBAIBDw8WAh8ABSlCdXNjYW5kbyBwcm9kdWN0b3MgcXVlIGNvbnRlbmdhbjogPGI+PC9iPmRkAgMPPCsACwEADxYKHglQYWdlQ291bnQCEx4QQ3VycmVudFBhZ2VJbmRleAIBHgtfIUl0ZW1Db3VudAIPHghEYXRhS2V5cxYPBQYwNjAzNjkFBjA2MDM3MwUGMDYwMzM4BQYwNjAwMDEFBjA2MDE4OAUGMDYwMTkyBQYwNTg5MTAFBjA1ODkxMQUGMDU4OTEyBQYwNjA0ODcFBjA2MDE5NgUGMDYwMDY4BQYwNTk3OTcFBjA1OTc5MgUGMDYwMjQ3HhVfIURhdGFTb3VyY2VJdGVtQ291bnQCjwJkFgJmD2QWHgICD2QWAmYPZBYCZg8VEQYwNjAzNjkDMDYwBjA2MDM2OQYwNjAzNjkyR3VpdGFyIEhlcm8gTWV0YWxsaWNhICAgICAgICAgICAgICAgICAgICAgICAgICAgICADUFMzBFBTMyANcGxheXN0YXRpb24gMxRhY3RpdmlzaW9uICAgICAgICAgIBRtdXNpY2EgICAgICAgICAgICAgIEI8c3B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yODE1PHNwYW4gY2xhc3M9IlRleHRvcHJlY2lvdGFjaGFkbyI+MjksOTUmZXVybzs8L3NwYW4+IC0FMjYsOTVkAgUPZBYCZg8VBwYwNTkyODIGMDU5MjgyMkdob3N0YnVzdGVycyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgBERWRCAGMDU5MjgyNTxzcGFuIGNsYXNzPSJUZXh0b3ByZWNpb3RhY2hhZG8iPjQ5LDk1JmV1cm87PC9zcGFuPiAtBTQ2LDk1ZAIGD2QWAmYPFQcGMDU5Mjg0BjA1OTI4NDJHaG9zdGJ1c3RlcnMgKENvbGVjY2lvbmlzdGEpICAgICAgICAgICAgICAgICAgICAgIARQUzMgBjA1OTI4NDU8c3BhbiBjbGFzcz0iVGV4dG9wcmVjaW90YWNoYWRvIj43OSw5NSZldXJvOzwvc3Bhbj4gLQU3NCw5NWQCBw9kFgJmDxUHBjA1OTE3OQYwNTkxNzkyTmFtY28gTXVzZXVtIFZpcnR1YWwgQXJjYWRlICAgICAgICAgICAgICAgICAgICAgICAEWDM2MAYwNTkxNzk1PHNwYW4gY2xhc3M9IlRleHRvcHJlY2lvdGFjaGFkbyI+MjksOTUmZXVybzs8L3NwYW4+IC0FMjYsOTVkAgEPDxYCHwAFAzI1OWRkZNzHWaPRjERu7Z1AyyTpE9nkeZc0");



    
    
    try{
      int returnCode = client.executeMethod(method);

      if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
        System.err.println("The Post method is not implemented by this URI");
        // still consume the response body
        method.getResponseBodyAsString();
      } else {
        br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
        String readLine;
        while(((readLine = br.readLine()) != null)) {
          System.err.println(readLine);
      }
      }
    } catch (Exception e) {
      System.err.println(e);
    } finally {
      method.releaseConnection();
      if(br != null) try { br.close(); } catch (Exception fe) {}
    }

  }
}
           
